package keyword

// DiscountStrategy 打折策略接口
type DiscountStrategy interface {
	ApplyDiscount(price float64) float64
}

// SeventyFivePercentDiscount 75%策略
type SeventyFivePercentDiscount struct{}

func (d SeventyFivePercentDiscount) ApplyDiscount(price float64) float64 {
	return price * 0.75
}

// EightyFivePercentDiscount 85%策略
type EightyFivePercentDiscount struct{}

func (d EightyFivePercentDiscount) ApplyDiscount(price float64) float64 {
	return price * 0.85
}

// NinetyFivePercentDiscount 95%策略
type NinetyFivePercentDiscount struct{}

func (d NinetyFivePercentDiscount) ApplyDiscount(price float64) float64 {
	return price * 0.95
}

// Book 的结构体
type Book struct {
	Title    string
	Price    float64
	Discount DiscountStrategy
}

// SetDiscount 设置打折策略
func (b *Book) SetDiscount(discount DiscountStrategy) {
	b.Discount = discount
}

// GetDiscountPrice 获取打折后的价格
func (b *Book) GetDiscountPrice() float64 {
	if b.Discount == nil {
		return b.Price
	}
	return b.Discount.ApplyDiscount(b.Price)
}
